package com.banyuan.controller;

import com.banyuan.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class LoginController {

    @RequestMapping("/loginPage")
    public String loginPage() {
        return "user/login";
    }

    @RequestMapping("/login")
    public ModelAndView login(User user, HttpSession httpSession) {
        System.out.println(user);
        ModelAndView success = new ModelAndView("success");
        ModelAndView lose = new ModelAndView("user/login");
        if (user.getName().equals("zhangsan") && user.getPassword().equals("123")) {
            httpSession.setAttribute("user",user);
            success.addObject("msg","欢迎" + user.getName() + "回来");
            return success;

        } else {
            lose.addObject("msg","密码或者账号不正确");
            return lose;
        }
    }

    @RequestMapping("/read")
    public String readPage() {
        return "user/read";
    }

}
